package com.xujicheng.algorithm.sort;

import java.util.Arrays;
import java.util.Random;

public class QuickSort<T extends Comparable> extends BaseSort<T> {

    @Override
    protected void sortDesc(Object[] objects) {
        sort(0,objects.length,objects);
    }

    @Override
    protected void sortAsc(Object[] objects) {
        sort(0,objects.length-1,objects);
    }

    private void sort(int left,int right,Object[] objects){

    }


    public static void main(String[] args) {
        final int maxLength = 100000000;
        int [] nums = new int[maxLength];
        for(int i = 0;i<maxLength-1;i++){
            nums[i] = new Random().nextInt(maxLength);
        }
        int i = 0;
        int j = maxLength-1;
        long start = System.currentTimeMillis();
        aaa(nums, i, j);
        System.out.println("总共："+(System.currentTimeMillis()-start)+"ms");
        System.out.println(Arrays.toString(nums));
    }

    private static void aaa(int[] sorts, int i, int j) {
        if(j>i) {
            int temp = sorts[i];
            int left = i;
            int right = j;
            while (left != right) {
                while (sorts[right] >= temp && left < right) {
                    right--;
                }
                while (sorts[left] <= temp && left < right) {
                    left++;
                }
                if (left < right) {
                    int tmp = sorts[right];
                    sorts[right] = sorts[left];
                    sorts[left] = tmp;
                }
            }
            if (right > i) {
                sorts[i] = sorts[right];
                sorts[right] = temp;

            }
            aaa(sorts, i, right - 1);
            aaa(sorts, right + 1, j);
        }

    }
}
